//
//  ARScanBottomPromptView.m
//  CGTN
//
//  Created by YangTengJiao on 2019/5/29.
//  Copyright © 2019 YangTengJiao. All rights reserved.
//

#import "ARScanBottomPromptView.h"

@interface ARScanBottomPromptView ()
@property (nonatomic,strong) UIView *guideView;
@property (nonatomic,strong) UIImageView *guideOneImageView;
@property (nonatomic,strong) UILabel *guideOneLabel;

@property (nonatomic,strong) UIImageView *guideTwoImageView;
@property (nonatomic,strong) UILabel *guideTwoLabel;

@property (nonatomic,strong) UIImageView *guideThreeImageView;
@property (nonatomic,strong) UILabel *guideThreeLabel;

@property (nonatomic,strong) UIImageView *guideFourImageView;
@property (nonatomic,strong) UILabel *guideFourLabel;


//引导页面 最终
@property (nonatomic,strong) UIImageView *lastGuideImageView;
@property (nonatomic,strong) UILabel *lastGuideLabel;

@property (nonatomic,assign) BOOL isOverGuide;
@end
@implementation ARScanBottomPromptView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView {
    self.bgButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.bgButton.frame = self.bounds;
    self.bgButton.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [self.bgButton addTarget:self action:@selector(bgButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.bgButton];
    
    /**
    self.topLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, (KIsiPhoneX?163:101), ScreenTJWidth-32-32, 88)];
    self.topLabel.font = FontTJ(18);
    self.topLabel.textColor = [UIColor whiteColor];
    self.topLabel.numberOfLines = 0;
    self.topLabel.textAlignment = NSTextAlignmentCenter;
    self.topLabel.text = KBottomPromptTop;
    [self addSubview:self.topLabel];
    
//    self.topOneLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, (KIsiPhoneX?154:100), ScreenTJWidth-60-60, 44)];
//    self.topOneLabel.font = FontTJ(18);
//    self.topOneLabel.textColor = [UIColor whiteColor];
//    self.topOneLabel.numberOfLines = 0;
//    self.topOneLabel.textAlignment = NSTextAlignmentCenter;
//    self.topOneLabel.text = KBottomPromptTopOne;
//    [self addSubview:self.topOneLabel];
//
//    self.topTwoLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, (KIsiPhoneX?210:156), ScreenTJWidth-60-60, 44)];
//    self.topTwoLabel.font = FontTJ(18);
//    self.topTwoLabel.textColor = [UIColor whiteColor];
//    self.topTwoLabel.text = KBottomPromptTopTwo;
//    self.topTwoLabel.numberOfLines = 0;
//    self.topTwoLabel.textAlignment = NSTextAlignmentCenter;
//    [self addSubview:self.topTwoLabel];
    
    self.leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, ScreenTJHeight-(KIsiPhoneX?172:172)-44, 118, 44)];
    self.leftLabel.font = FontTJ(18);
    self.leftLabel.textColor = [UIColor whiteColor];
    self.leftLabel.text = KBottomPromptleft;
    self.leftLabel.textAlignment = NSTextAlignmentCenter;
    self.leftLabel.numberOfLines = 0;
    [self addSubview:self.leftLabel];
    
    self.rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenTJWidth-23-140, ScreenTJHeight-(KIsiPhoneX?172:172)-44, 140, 44)];
    self.rightLabel.font = FontTJ(18);
    self.rightLabel.textColor = [UIColor whiteColor];
    self.rightLabel.text = KBottomPromptRight;
    self.rightLabel.numberOfLines = 0;
    self.rightLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.rightLabel];
    //42 132   14 44  29+15-7
    self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(70, ScreenTJHeight-(KIsiPhoneX?123:123)-44, 14, 44)];
    [self.leftImageView setImage:kGetARImage(@"箭头")];
    [self addSubview:self.leftImageView];
    
    self.rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenTJWidth-85, ScreenTJHeight-(KIsiPhoneX?123:123)-44, 14, 44)];
    [self.rightImageView setImage:kGetARImage(@"箭头")];
    [self addSubview:self.rightImageView];
    
    self.centerLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, ScreenTJHeight-(KIsiPhoneX?240:240)-50, ScreenTJWidth-40-40, 50)];
    self.centerLabel.font = FontTJ(18);
    self.centerLabel.textColor = [UIColor whiteColor];
    self.centerLabel.text = KBottomPromptCenter;
    self.centerLabel.numberOfLines = 0;
    self.centerLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.centerLabel];
    
    self.centerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenTJWidth/2.0-14/2.0, ScreenTJHeight-(KIsiPhoneX?128:128)-95, 14, 95)];
    [self.centerImageView setImage:kGetARImage(@"箭头")];
    [self addSubview:self.centerImageView];
     */
    [self initGuideView];
    
}
- (void)initGuideView {
    CGFloat imageH = 180;
    CGFloat imageW = 148;
    CGFloat margin = 15;
    CGFloat bottomMargin = 18;
    CGFloat topMargin = 30;
    CGFloat titleH = 66;
    self.guideView = [[UIView alloc]initWithFrame:self.bounds];
    [self addSubview:self.guideView];
    
    self.guideOneLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.center.x - margin - imageW, self.center.y - titleH - topMargin, imageW, titleH)];
    self.guideOneLabel.font = FontTJ(18);
    self.guideOneLabel.textColor = [UIColor whiteColor];
    self.guideOneLabel.textAlignment = NSTextAlignmentCenter;
    self.guideOneLabel.numberOfLines = 0;
    self.guideOneLabel.text = KGuideLongPress;
    [self.guideView addSubview:self.guideOneLabel];
    
    self.guideTwoLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.center.x + margin, self.center.y - titleH - topMargin, imageW, titleH)];
    self.guideTwoLabel.font = FontTJ(18);
    self.guideTwoLabel.textColor = [UIColor whiteColor];
    self.guideTwoLabel.textAlignment = NSTextAlignmentCenter;
    self.guideTwoLabel.numberOfLines = 0;
    self.guideTwoLabel.text = KGuidePinch;
    [self.guideView addSubview:self.guideTwoLabel];
    
    
    self.guideOneImageView = [[UIImageView alloc]initWithImage:kGetARImage(@"AR_GuideLongPress")];
    self.guideOneImageView.frame = CGRectMake(self.center.x - margin - imageW, self.center.y - titleH - imageH, imageW, imageH);
    [self.guideView addSubview:self.guideOneImageView];
    
    self.guideTwoImageView = [[UIImageView alloc]initWithImage:kGetARImage(@"AR_GuidePinch")];
    self.guideTwoImageView.frame = CGRectMake(self.center.x + margin, self.center.y - titleH - imageH, imageW, imageH);
    [self.guideView addSubview:self.guideTwoImageView];
    
    self.guideThreeImageView = [[UIImageView alloc]initWithImage:kGetARImage(@"AR_GuideDoubleTap")];
    self.guideThreeImageView.frame = CGRectMake(self.center.x - margin - imageW, self.center.y + bottomMargin, imageW, imageH);
    [self.guideView addSubview:self.guideThreeImageView];
    
    self.guideFourImageView = [[UIImageView alloc]initWithImage:kGetARImage(@"AR_GuideMoveTo")];
    self.guideFourImageView.frame = CGRectMake(self.center.x + margin , self.center.y + bottomMargin, imageW, imageH);
    [self.guideView addSubview:self.guideFourImageView];
    
    self.guideThreeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.center.x - margin - imageW, CGRectGetMaxY(self.guideThreeImageView.frame) , imageW, titleH)];
    self.guideThreeLabel.font = FontTJ(18);
    self.guideThreeLabel.textColor = [UIColor whiteColor];
    self.guideThreeLabel.textAlignment = NSTextAlignmentCenter;
    self.guideThreeLabel.numberOfLines = 0;
    self.guideThreeLabel.text = KGuideDoubleTap;
    [self.guideView addSubview:self.guideThreeLabel];
    
    self.guideFourLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.center.x + margin, CGRectGetMaxY(self.guideFourImageView.frame), imageW, titleH)];
    self.guideFourLabel.font = FontTJ(18);
    self.guideFourLabel.textColor = [UIColor whiteColor];
    self.guideFourLabel.textAlignment = NSTextAlignmentCenter;
    self.guideFourLabel.numberOfLines = 0;
    self.guideFourLabel.text = KGuideMoveTo;
    [self.guideView addSubview:self.guideFourLabel];
    
    //添加点击事件
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGuideAction)];
    [self.guideView addGestureRecognizer:tapGes];
}

- (void)initLastGuideView {
    [self.guideView removeFromSuperview];
    CGFloat margin = 44;
    CGFloat lableH = 80;
    self.lastGuideImageView = [[UIImageView alloc]initWithImage:kGetARImage(@"AR_graphics")];
    self.lastGuideImageView.frame = CGRectMake(self.center.x - self.lastGuideImageView.image.size.width * 0.5, self.center.y - self.lastGuideImageView.image.size.height * 0.5, self.lastGuideImageView.image.size.width, self.lastGuideImageView.image.size.height);
    [self addSubview:self.lastGuideImageView];
    
    self.lastGuideLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.lastGuideImageView.frame.origin.x - 25, self.lastGuideImageView.frame.origin.y - margin - lableH, self.lastGuideImageView.image.size.width + 50, lableH)];
    self.lastGuideLabel.font = FontTJ(18);
    self.lastGuideLabel.textColor = [UIColor whiteColor];
    self.lastGuideLabel.textAlignment = NSTextAlignmentCenter;
    self.lastGuideLabel.numberOfLines = 0;
    self.lastGuideLabel.text = KGuideMoveToBuilding;
    [self addSubview:self.lastGuideLabel];
    
    self.isOverGuide = YES;
}
- (void)bgButtonAction {
    if (!self.isOverGuide) {
//        self.leftLabel.hidden = YES;
//        self.leftImageView.hidden = YES;
//        self.centerImageView.hidden = YES;
//        self.centerLabel.hidden = YES;
//        self.rightLabel.hidden = YES;
//        self.rightImageView.hidden = YES;
//        self.topLabel.hidden = YES;
    } else {
        [self removeFromSuperview];
    }
}
- (void)tapGuideAction {
    [self initLastGuideView];
}

@end
